<script type="text/javascript">
	function loadDeliveryOrderInfo() {
		var orderNo = $('#DeliveryOrderNo').val();
		$.post('transOrderScan.do?loadTransOrderLastestScanInfo',{orderNo:orderNo},function(result){
			   if (result.success){
	           	 $("#DeliveryOrderScanForm").form('load', result.obj);
	           	 if('${(DELIVERY_SCAN_AUTO_SAVE)!}'=='Y') {
	           		 window.setTimeout("saveDeliveryOrderScan()" , 500);
	           	 }
	           	
	           } else {
	        	   showMsg(result.msg,3000);
	           }
	        },'json');
	}
	
	function saveDeliveryOrderScan() {
		var validate = $('#DeliveryOrderScanForm').form("validate");
		if(validate) {
			var actionurl = $('#DeliveryOrderScanForm').attr('action');//提交路径
			var formData = new Object();

			var fields = $('#DeliveryOrderScanForm').serializeArray(); //自动序列化表单元素为JSON对象  

			$.each(fields, function(i, field) {
				printLog(field.name + "=" + field.value);
				formData[field.name] = field.value;
			});
			printLog(formData);
			jmaxAjax(actionurl,formData,function(rs) {
				resetScanInfo('DeliveryOrderScanForm','deliveryScanWebsite','${(personWebsiteId)!}');
				//设置默认派件人和派件电话
				$('#deliveryPersonName').val('${(user.name)!}');
				$('#deliveryPersonPhone').val('${(user.telephone)!}');
				reloadDeliveryOrderScan();
			});
		}
	}
	//表格查询  
	function reloadDeliveryOrderScan() {
		var params = DeliveryOrderScan_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		DeliveryOrderScan_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		DeliveryOrderScan_list.datagrid('unselectAll');
		DeliveryOrderScan_list.datagrid('uncheckAll');
	}
	
	function deleteDeliveryOrderScan() {
		var rows = DeliveryOrderScan_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('transOrderScan.do?deleteTransOrderScanItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadDeliveryOrderScan();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function addDeliveryOrderScan() {
		resetScanInfo('DeliveryOrderScanForm','deliveryScanWebsite','${(personWebsiteId)!}');
	}
</script>
<div class="easyui-layout" data-options="fit:true">
	 <div data-options="region:'north',border:false" style="height:100px;overflow: hidden;background:#F4F4F4">
       	<div id="DeliveryOrderScan_toolbar" style="border-bottom:1px solid #ddd;height: auto">
			<@eu.linkbutton showName="新增" shiro="trans:deliveryOrderScan:add" iconCls="icon-add" onclick="addDeliveryOrderScan()"/>
			<@eu.linkbutton showName="更新或保存" shiro="trans:deliveryOrderScan:saveOrUpdate" iconCls="icon-save" onclick="saveDeliveryOrderScan()"/>
		</div>
	    <form id="DeliveryOrderScanForm" action="transOrderScan.do?sureDeliveryScan">
	    	<table>
	    		<tr>
	    			<td class="tbLabel" rowspan="2">运单号:</td>
	    			<td rowspan="2"><input id="DeliveryOrderNo" style="height: 40px;width:200px;" name="orderNo" class="easyui-validatebox textbox" onchange="loadDeliveryOrderInfo()"/></td>
	    			<td class="tbLabel">派件人:</td>
	    			<td><input id="deliveryPersonName" class="easyui-validatebox textbox" name="deliveryName" value="${(user.name)!}"/></td>
	    			<td class="tbLabel">派件人电话:</td>
	    			<td>
						<input id="deliveryPersonPhone" class="easyui-validatebox textbox"  name="deliveryPhone" value="${(user.telephone)!}"/>	    			
					</td>
					
	    		</tr>
	    		<tr>
	    			<td class="tbLabel">当前网点:</td>
	    			<td>
	    				<input type="hidden" name="startWebsiteId" />
	    				<@eu.comboBox disabled="true" id="deliveryScanWebsite" url="transWebSite.do?loadWebsiteCombox&value=${(personWebsiteId)!}" name="currentWebsiteId" required="true" />
	    			</td>
	    			<td>目的站:</td>
	    			<td>
	    				<@eu.comboBox disabled="true" url="transWebSite.do?loadWebsiteCombox" name="endWebsiteId" required="true" />
	    			</td>
	    		</tr>
	    	</table>
	    </form>
     </div>
	<div data-options="region:'center',border:false,title:'扫描清单'">
		<@eu.datagrid id="DeliveryOrderScan_list" idField="id" 
			 url="transOrderScan.do?loadDeliveryScanList&scanType=4&creator=${(user.loginName)!}" rownumbers="true" toolbar="#DeliveryOrderScanListSearch"
			 item="com.xdtech.trans.vo.OrderDeliveryScanItem"/>
		<div id="DeliveryOrderScanListSearch">
			<div id="DeliveryOrderScanToolbar" style="height: auto">
				<@eu.linkbutton showName="删除" shiro="trans:deliveryOrderScan:delete" iconCls="icon-remove" onclick="deleteDeliveryOrderScan()"/>
			</div>
		</div>
	</div>
</div>